#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import render_template, request
from app import app, db
from models import Foods, OrderDeals, Orders

@app.route('/', methods=['GET','POST'])
def index():
    if request.method == "POST":
        pass
    foods = Foods.query.all()
    return render_template("index.html", foods=foods, total_count=len(foods), page_count=len(foods))


@app.route('/add_order_deals', methods=['POST'])
def add_order_deals():
    if request.method == "POST":
        args = request.values
        order_id = args.get('order_id', '')
        if not order_id:
            table_num = args.get('table_num', '')
            order = Orders(table_num=table_num)
            db.session.add(order)
            order_id = order.order_id
    deals = OrderDeals(order_id=order_id, food_id=args.food_id)
    return 1


"""
url取值
To access parameters submitted in the URL (?key=value) you can use the args attribute:

searchword = request.args.get('key', '')

value 取值
$.post($SCRIPT_ROOT + '/update_file/' + file_name,
           { 'newtext': $(".modal-body textarea").val() },
           //{ 'newtext': "abc" },
           function(data,status){
           //  if(status == "success")
           //  window.location.href="{{ url_for('refresh') }}";

      });
value = request.values.get('newtext', 0)
===================================================================
form 取值
print request.form.get('myid')    #input
print request.form.getlist('mychecks')    #check组


<form method="post" action="/mockservice"  method = "post">
      ...

    <div class="form-group">
        <label>data <font style="color:#a94442" size="2">
        <input class="form-control" id="data" name="data">
    </div>
    <div class="form-group">
        <button  type="submit" class="btn btn-default">Submit &nbsp</button>
    </div>
</form>

class MockCreate(Form):
    user_email = StringField("email address",[validators.Email()])
    api = StringField("api",[Required()])
    submit = SubmitField("Submit")
    code = IntegerField("code example: 200",[Required()])
    alias = StringField("alias for api")
    data = TextAreaField("json format",[Required()])

@app.route("/mockservice",methods=['GET','POST'])
def MockController():
    form = MockCreate()
    code = form['code']
    api = form['api']
    return render_template("testf.html",api=api,data=code)
"""
if __name__ == '__main__':

    app.run()